package club.monkeywood.ad.dmp.util

import com.typesafe.config.ConfigFactory
import org.apache.commons.pool2.impl.GenericObjectPoolConfig
import redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig}

object JedisPools {

    val config = new JedisPoolConfig()
    //最大连接数,
    config.setMaxTotal(-1)
    //最大空闲连接数
    config.setMaxIdle(-1)
    //当调用borrow Object方法时，是否进行有效性检查 -->
    config.setTestOnBorrow(true)

    //10000代表超时时间（10秒）
    //
    val load = ConfigFactory.load()
    val host = load.getString("jedis.host")
    val password = load.getString("jedis.password")
    private val pool = new JedisPool(config, host, 6379, 10000, password,0)

    def getConnection(): Jedis = {
        pool.getResource
    }

}
